package com.mes.license_demo;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * @author ：zb
 * @date ：Created in 2019/5/13 0013 15:53
 * @description：
 */

public class TimeUtil {
    public static String getCurDate(){
        DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateTime=LocalDateTime.now(ZoneOffset.of("+8")).format(formatter);
        return dateTime;
    }

    public static String getNextYear(Integer years){
        DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateTime=LocalDateTime.now(ZoneOffset.of("+8")).plusYears(years).format(formatter);
        return dateTime;
    }

    public static String getCurDay(){
        DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyyMMdd");
        String dateTime=LocalDateTime.now(ZoneOffset.of("+8")).format(formatter);
        return dateTime;
    }

    public static String getD8Date(String str){
        if (str.split(":").length<2){
            str=str+" 00:00:00";
        }
        DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime=LocalDateTime.parse(str,formatter);
        LocalDateTime localDateTime = dateTime.minusHours(8);
        dateTime.plusHours(8);
        return localDateTime.toString().replaceAll("T"," ");
    }

    public static Integer compare(String str){
        str=str.split(" ")[0];
        str=str.replaceAll("-","");
        DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyyMMdd");
        String datetime= LocalDateTime.now(ZoneOffset.of("+8")).format(formatter);
        int i = Integer.valueOf(str) - Integer.valueOf(datetime);
        return i;
    }

    public static void main(String[] args) {
        System.out.println(getD8Date("2019-06-04 13:44:22"));
    }


}
